package cn.wolfcode.luowowo.common;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.io.Serializable;

@Setter
@Getter
@ToString
public class ResultDev<T> implements Serializable {
    public static final String SUCCESS_MESSAGE="操作成功";
    public static final String ERROR_MESSAGE="系统异常";
    public static final int SUCCESS_CODE=200;//成功编码
    public static final int ERROR_CODE=500000;//错误编码

    private Integer code;
    private String msg;
    private T data;
    public ResultDev(){}
    private ResultDev(int code,String msg,T data){
        this.code= code;
        this.msg= msg;
        this.data= data;
    }

    private static <T> ResultDev<T> success(T data){
        return new ResultDev<>(SUCCESS_CODE,SUCCESS_MESSAGE,data);
    }
    private static <T> ResultDev<T> success(){
        return new ResultDev(SUCCESS_CODE,SUCCESS_MESSAGE,null);
    }
    private static <T> ResultDev<T> success(String msg,T data){
        return new ResultDev<>(SUCCESS_CODE,msg,data);
    }
    private static <T> ResultDev<T> error(){
        return new ResultDev(SUCCESS_CODE,SUCCESS_MESSAGE,null);
    }
    public boolean hasError(){
        //状态码!=200,说明有错误
        return this.code!=SUCCESS_CODE;
    }



}
